package cn.itcast.daoTest;

import cn.itcast.dao.ItemMapper;
import cn.itcast.domain.Item;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring/applicationContext-*.xml"})
public class ItemMapperTest {

    @Autowired
    private ItemMapper itemMapper;

    @Test
    public void saveItemList() {
    }

    @Test
    public void getItemById() {
    }

    @Test
    public void updateItem(){
        Item item = new Item();
        item.setId(30);
        item.setName("阿拉斯加的方式打飞机");
        Integer integer = itemMapper.updateItem(item);
        System.out.println(integer+"++++++++++++++++++++++++++++++");
    }

    @Test
    public void getItemByName() {
        Item item = itemMapper.getItemByName();
        System.out.println(item);
    }

    /*@Test
    public void findItemList(){
        List<Item> itemList = itemMapper.findItemList();
        System.out.println(itemList.size()+" ++++++++++++++++++++++");
    }*/

    @Test
    public void insertItem() {
        Item item = new Item("imac", 20000, new Date(), "苹果本很贵");
        Item item1 = new Item("imac1", 20000, new Date(), "苹果本很贵");
        Item item2 = new Item("imac2", 20000, new Date(), "苹果本很贵");
        Item item3 = new Item("imac3", 20000, new Date(), "苹果本很贵");
        Item item4 = new Item("imac4", 20000, new Date(), "卧槽，苹果本很贵啦！");
        Integer integer = itemMapper.insertItem(item);
        Integer integer1 = itemMapper.insertItem(item1);
        Integer integer2 = itemMapper.insertItem(item2);
        Integer integer3 = itemMapper.insertItem(item3);
        Integer integer4 = itemMapper.insertItem(item4);
        System.out.println(item.getId() + " " + integer1 + " " + integer2 + " " + integer3 + " " + integer4 + "===================================");

    }

    @Test
    public void findItemList2(){
        List<Integer> idList = new ArrayList<>();
        idList.add(1);

        List<Item> itemList = itemMapper.findItemList(idList);
        System.out.println(itemList);
        System.out.println(itemList.size());


    }



}